<?php
class Funlist_model extends Model {
	
	function Funlist_model(){
		parent::Model();
		
	}
	//getting subcategeoies when parentid is given otherwise getting root categeories 
	function categeories($parentid)
	{
		$this->db->where('parentid',$parentid);
		$this->db->order_by('catname');
		$query = $this->db->get('categeory');
		return $query;
	}
	//getting images when id of subcategeory is given
	function funlists($id,$limitone)
	{
		$this->db->where('images.parentid',$id);
		$this->db->order_by('images.id','desc');
		$this->db->from('images');
		$this->db->select('images.id,images.parentid,categeory.catname');
		$this->db->join('categeory','categeory.id= images.parentid');
		
		//$this->db->select('images.id,title');
		
		if($limitone=='yes')
		{
			$this->db->limit(1);
		}
		$query = $this->db->get();
		return $query;
	}
	function recent_categeories()
	{
        $images=array();
        $recentcategeories=array();
		$this->db->order_by('update_date','desc');
		$this->db->where('parentid !=',0);
		$this->db->select('catname,id');
		$this->db->limit(3);
		$query = $this->db->get('categeory');
		$recentcategeories = $query->result();
		//print_r($recentcategeories);
		/*foreach($recentcategeories as $item)
		{
			
			$query = $this->funlists($item['id'],'yes');
			$image = $query->result_array();
			if(isset($image[0]['id']))
			{
            $images[$item['id']] = $image[0]['id'];
			}
           			
		}*/
		return $recentcategeories;
		
	}
	function getcategeoryname()
	{
        $this->db->where('id',$this->uri->segment(3));
       	$this->db->select('catname,id');
		$query=$this->db->get('categeory');
		$result = $query->result();
		if(!empty($result))
		{
		$categeoryname= $result['0']->catname;
		}
		else
		{
			$categeoryname = 'Funny Pictures';
		}
		return $categeoryname;
	}
		
}
   
?>